package com.kgc.easyshopping.controller;

import com.github.pagehelper.PageInfo;
import com.kgc.easyshopping.entity.News;
import com.kgc.easyshopping.service.NewsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
public class NewsController {
    private Logger log = LoggerFactory.getLogger(this.getClass());

    @Resource
    private NewsService newsService;

    @GetMapping("news")
    public PageInfo<News> selectPageInfo(@RequestParam Map<String, Object> params){
        Map<String, Object> map = new HashMap<>();

        int pageNum =  Integer.parseInt((String) params.get("pageNum"));
        int pageSize = Integer.parseInt((String) params.get("pageSize"));
        map.put("pageNum", pageNum);
        map.put("pageSize", pageSize);

        String title = (String) params.get("title");
        if(title!=null && title!=""){
            map.put("title","%"+title+"%");
        }
        return newsService.selectPageInfo(map);
    }

}
